package com.xuecheng.order.controller;

import com.xuecheng.commons.model.vo.OrdersVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.web.exceptions.BusinessException;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.order.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 订单前端控制器
 * </p>
 *
 * @author 七安
 */
@Slf4j
@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 创建订单
     *
     * @param coursePubId 课程发布id
     * @return 结果
     */
    @PostMapping("/create/{coursePubId}")
    public ResponseResult<String> createOrder(@PathVariable("coursePubId") Long coursePubId) throws BusinessException {
        return ordersService.createOrder(coursePubId);
    }

    /**
     * 查询支付结果
     * @param orderNo 查询支付结果
     * @return 订单信息
     */
    @GetMapping("/{orderNo}")
    public ResponseResult<OrdersVo> findPayResult(@PathVariable("orderNo") String orderNo) throws BusinessException {
       return ordersService.findPayResult(orderNo);
    }
}
